import {request} from "./utils.js";

const isMock = false;

export function register(data) {
    if (isMock) {
        return Promise.resolve(true);
    }
    return request({
        url: '/user/register',
        data,
    });
}

export function login(data) {
    if (isMock) {
        return Promise.resolve({
            token: '123123',
            "user": {
                "userId": "1",
                "userName": "张衡",
                "password": "$2a$1050yqifUsEluEEbbEL8He9DeFvnXj7yeL3vgplBipYW/U/NseM5azW",
                "sex": "1",
                "height": "175",
                "weight": "75",
                "phone": "13541225215",
                "createTime": "2023-04-26T17:21:11"
            }
        });
    }
    return request({
        url: '/user/login',
        data,
    });
}

export function question(data) {
    if (isMock) {
        return Promise.resolve('乳房囊性增生病,乳腺小叶增生，乳腺增生症,乳腺结构不良症,乳痛症');
    }
    return request({
        url: '/query/question',
        method: 'get',
        params: data,
    });
}

export function logout(data) {
    if (isMock) {
        return Promise.resolve(true);
    }
    return request({
        url: '/user/logout',
        data,
    });
}

export function history(data) {
    if (isMock) {
        return Promise.resolve(Array.from({length: 100}, (_, i) => {
            return {
                id: i,
                "createTime": "2023-04-26T21:49:33",
                "userId": "1",
                "question": "乳腺增生别名" + i,
                "answer": "乳房性增生病,乳腺小叶增生，乳腺增生症,乳腺结构不良症,乳痛症" + i,
                "queryTime": "2023-04-26T21:49:34",
            }
        }));
    }
    return request({
        url: '/query/history',
        data,
    });
}

export function update(data) {
    if (isMock) {
        return Promise.resolve(true);
    }
    return request({
        url: '/user/update',
        data,
    });
}